<template>
	<view>
		<form @submit="formSubmit" @reset="formReset">
			<view class="title">switch</view>
			<view>
				<switch name="switch" />
			</view>
			<view class="title">用户名</view>
			<input class="uni-input" name="username" placeholder="这是一个输入框" />
			<view class="title">密码</view>
			<input class="uni-input" name="password" placeholder="这是一个输入框" />
			<view class="title">radio</view>
			<radio-group name="radio">
				<label>
					<radio value="radio1" /><text>选项一</text>
				</label>
				<label>
					<radio value="radio2" /><text>选项二</text>
				</label>
			</radio-group>
			<view class="title">checkbox</view>
			<checkbox-group name="checkbox">
				<label>
					<checkbox value="checkbox1" /><text>选项一</text>
				</label>
				<label>
					<checkbox value="checkbox2" /><text>选项二</text>
				</label>
			</checkbox-group>
			<button size="mini" form-type="submit">Submit</button>
			<button size="mini" form-type="reset">Reset</button>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		methods: {
			async formSubmit(e) {
				console.log('原始数据', e.detail.value)
				const { data: { data, meta } } = await uni.request({
					method:"POST",
					url:`http://127.0.0.1:8888/api/private/v1/login`,
					data:e.detail.value,
				})
				uni.setStorage({
					key:'token',
					data:data.token
				})
				uni.chooseImage({
					count: 6, //默认9
					success: function (res) {
						console.log(JSON.stringify(res.tempFilePaths));
					}
				});
				uni.uploadFile({
							url: 'https://www.example.com/upload', //仅为示例，非真实的接口地址
							filePath: tempFilePaths[0],
							name: 'file',
							formData: {
								'user': 'test'
							},
							success: (uploadFileRes) => {
								console.log(uploadFileRes.data);
							}
						});
				console.log('form发生了submit事件，携带数据为：' , JSON.stringify(e.detail.value))
			},
			formReset: function(e) {
				console.log('清空数据')
			}

		}
	}
</script>

<style>

</style>
